package com.fcat.springboot.mail.service.impl;


import com.fcat.springboot.mail.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * spring:
 *   mail:
 *     default-encoding: UTF-8
 *     host: smtp.exmail.qq.com
 *     username: liuxiangfei@tsuantone.com
 *     password: riPjsnbs32q8DQds
 *     port: 465
 *     # 使用SSL方式
 *     properties:
 *       mail:
 *         smtp:
 *           socketFactory:
 *             class: javax.net.ssl.SSLSocketFactory
 */
@Service
public class MailServiceImpl implements MailService {

    @Autowired
    private JavaMailSender mailSender;

    @Override
    public void sendEmail(String from, String[] to, String subject, String content) {

        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSubject(subject);
        message.setText(content);
        mailSender.send(message);

    }
}
